package com.scs.application.modules.dept.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.base.annotation.MatrCanPass;
import com.scs.application.modules.base.util.MatrPassUtil;
import com.scs.application.modules.dept.entity.ApplyItem;
import com.scs.application.modules.dept.service.ApplyItemService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 科室请领单明细 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/dept/applyItem")
public class ApplyItemController extends CrudController<ApplyItemService, ApplyItem>{
    @Autowired
    private MatrPassUtil matrPassUtil;
    @PostMapping("/saveBatch")
    public RestResult saveBatch(@Valid @RequestBody List<ApplyItem> entityList) {
        service.saveBatch(entityList);
        return RestResult.ok("批量添加成功",  entityList);
    }


    /**
    * @Description：科室请领需求批量操作
    */
    @PostMapping("/saveBatchForApplyDemand")
    @MatrCanPass(businessType = "apply")
    public RestResult saveBatchForApplyDemand(@Valid @RequestBody List<ApplyItem> entityList) {
        //matrPassUtil.ckeckMatrPass("apply", entityList.stream().map(ApplyItem::getMatrId).collect(Collectors.toList()));
        service.saveBatchForApplyDemand(entityList);
        return RestResult.ok("批量添加成功",  entityList);
    }
}
